package com.pro.springbootshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pro.springbootshop.entity.Cart;
import com.pro.springbootshop.entity.Wares;
import org.apache.ibatis.annotations.*;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    @Select("select * from cart where wares_id=#{waresId} and buyer_id=#{buyerId}")
    Cart selectCartById(int waresId,String buyerId);
    @Select("select * from cart where buyer_id=#{buyerId}")
    @Results(
            {
                    @Result(column = "cart_id",property = "cartId"),
                    @Result(column = "wares_id",property = "waresId"),
                    @Result(column = "wares_number",property = "waresNumber"),
                    @Result(column = "cart_state",property = "cartState"),
                    @Result(column = "wares_id",property = "wares",javaType = Wares.class,
                            one=@One(select = "com.pro.springbootshop.mapper.WaresMapper.selectById")
                    )
            }
    )
    List<Cart> selectCartShop(String buyerId);
    @Delete("delete from cart where wares_id=#{waresId}")
    void deleteCartByWaresId(int waresId);
}
